<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .col{
      background-color: yellow;
    }
    .colm{
      background-color: white;
    }
    input{
      display: block;
    }
  </style>
</head>
<body>
  <div >
    <input type="text" >
    <input type="text" >
    <input type="text" >
    <input type="text" >
    <input type="text" >
    <input type="text" >
    <input type="text" >
    <input type="button" value="按钮">
  </div>
  <script>
    var di = document.getElementsByTagName("input");
    // var box = document.querySelector('div')
    // box.querySelectorAll('input')

    // var dii = document.getElementsByTagName("input");
// console.log(dii);
    var dan = 1;

    for (let index = 0; index < di.length; index++) {
         di[index].onclick = function () {
          for (let index1 = 0; index1 < di.length; index1++){
            di[index1].classList.remove("col")
          }
            this.classList.add("col")
          }
         }
    // for (let index = 0; index < di.length; index++) {
    //   di[index].onclick = function () {
    //     // console.log(this.className);
    //     // di.input.classlist.add("colm");
    //     // this.backgroundColor = "yellow"
    //     // this.className ="col"
    //     di[index].classList.add("colm")
    //     this.classList.add("col")
    //   }   
    // }
  </script>
</body>
</html>